{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Dict{Symbol,Array{Tuple{Symbol,Int64},1}} with 6 entries:\n",
       "  :lower_bound => [(:markov_states,0),(:states,0),(:parameters,0)]\n",
       "  :arbitrage   => [(:markov_states,0),(:states,0),(:controls,0),(:markov_states…\n",
       "  :auxiliary   => [(:markov_states,0),(:states,0),(:controls,0),(:parameters,0)]\n",
       "  :felicity    => [(:markov_states,0),(:states,0),(:controls,0),(:parameters,0)]\n",
       "  :upper_bound => [(:markov_states,-1),(:states,0),(:parameters,0)]\n",
       "  :transition  => [(:markov_states,-1),(:states,-1),(:controls,-1),(:markov_sta…"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "include(\"quickdef.jl\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5-element Array{Tuple{Symbol,Int64},1}:\n",
       " (:markov_states,-1)\n",
       " (:states,-1)       \n",
       " (:controls,-1)     \n",
       " (:markov_states,0) \n",
       " (:parameters,0)    "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# import api:\n",
    "api = recipes[:transition]\n",
    "api\n",
    "# markov_states allowed at date t-1 and t\n",
    "# states allowed at date t-1\n",
    "# controls allowed at date t-1\n",
    "# parameters allowed at date t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Dict{Symbol,Array{Symbol,1}} with 4 entries:\n",
       "  :states        => [:a,:b]\n",
       "  :parameters    => [:p]\n",
       "  :markov_states => [:m0,:m1]\n",
       "  :controls      => [:x,:y]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# the model definition contains a list of symbols for each symbol type\n",
    "symbols = Dict(\n",
    "    :markov_states => [:m0, :m1],\n",
    "    :states => [:a, :b],\n",
    "    :controls => [:x, :y],\n",
    "    :parameters => [:p]\n",
    ")\n",
    "symbols"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "transition (generic function with 2 methods)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# can define functions out these symbols using usual timing conventions\n",
    "\n",
    "@quickargs symbols api begin\n",
    "function transition()\n",
    "        out = zeros(2)\n",
    "        out[1] = a(-1) + b(-1) + m0\n",
    "        out[2] = p*x(-1) + m1\n",
    "        return out\n",
    "end\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2-element Array{Float64,1}:\n",
       " 0.0\n",
       " 0.0"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# try it:\n",
    "s = zeros(2)\n",
    "x = zeros(2)\n",
    "p = zeros(1)\n",
    "m = zeros(2)\n",
    "transition(m,s,x,m,p)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 0.4.0",
   "language": "julia",
   "name": "julia-0.4"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "0.4.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
